Fearless Refactoring and

the Art of Argument-Free Rust

Ed Jones, RustConf ’24
  • I work at Canonical
  • I like clean code
  • I annoy my coworkers

industry’s hard problems

industry’s hard problems

  • requirements
  • politics
  • maintenance

what is maintainable?

what is maintainable?

  • simple
  • easily-understood
  • predictable

for whom does the coder code?

for whom does the coder code?

  • customers and consumers
  • coworkers
  • themselves

Fearless Refactoring

Fearless Refactoring

after making a change, the next time all tooling passes,
code likely still works as intended

good practices

good practices

  • match exhaustively
  • mutate in well-defined regions
  • limit unsafety

good code

good code

  • predictable
  • clear flow of concepts
  • obvious responsilbilities
  • sparingly weird

weird code

weird code

  • draws the eye
  • result of uncoordinated practices
  • resolved by debate

The Art of Argument-free Rust

The Art of Argument-free Rust

note: not debate-free

how we’ve avoided arguments

how we’ve avoided arguments

  • office hours (‘Rust Surgery’)
  • cross-team code-review
  • standardisation docs

standardisation docs

standardisation docs

  • provide a reference point for best-practices
  • provide rationale for particular decisions
  • show benefits with clear examples

the process

the process

  1. note repeated arguments
  2. write up generally-applicable notes
  3. review with a few experienced Rustaceans
  4. review with many Rustaceans
  5. release

the process (hard-mode)

  1. note repeated arguments
  2. write up generally-applicable notes
  3. review with a few experienced Rustaceans
  4. review with many Rustaceans
  5. release

the process (easy-mode)

the process (easy-mode)

github.com/canonical/rust-best-practices

what’s next?

what’s next?

  • more standards
  • automation

thanks for listening!